package com.haust.detail.controller;

import com.haust.commons.exception.DaoException;
import com.haust.commons.pojo.HaustResult;
import com.haust.detail.service.ItemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class ItemDetailController {

    @Autowired
    private ItemDetailService itemDetailService;

    /**
     * 通过 商品id，查找商品表中的信息
     *
     * @param itemId 商品id
     * @return
     */
    @PostMapping("/item/selectItemInfo")
    public HaustResult selectItemInfo(@RequestParam("id") Long itemId) {
        try {
            return itemDetailService.selectItemInfo(itemId);
        } catch (DaoException e) {
            return HaustResult.error(e.getMessage());
        }
    }

    /**
     * 通过商品id， 查找商品详情表中的信息
     *
     * @param itemId 商品id
     * @return
     */
    @PostMapping("/item/selectItemDescByItemId")
    public HaustResult selectItemDescByItemId(@RequestParam("itemId") Long itemId) {
       try {
           return itemDetailService.selectItemDescByItemId(itemId);
       }catch (DaoException e){
           return HaustResult.error(e.getMessage());
       }
    }


    /**
     * 根据商品id，查找商品规格表中的 的具体规格信息
     *
     * @param itemId 商品id
     * @return
     */
    @PostMapping("/item/selectTbItemParamItemByItemId")
    public HaustResult selectTbItemParamItemByItemId(@RequestParam("itemId") Long itemId) {
        try {
            return itemDetailService.selectTbItemParamItemByItemId(itemId);
        }catch (DaoException e){
            return HaustResult.error(e.getMessage());
        }
    }

}
